package resources;

public class Settings {
	private static volatile Settings instance;
	private boolean multipleWindowsOpen;
	private boolean tileOpenWindows;
	private boolean tileWindowsOpenResize;
	private int cpuCores;
	
	private Settings(){
		cpuCores=getSystemCores();
		multipleWindowsOpen=true;
		tileOpenWindows=true;
		tileWindowsOpenResize=true;
		
	}

	// This method is called getInstance. It uses a double - locking mechanism
	// to ensure
	// synchronization between threads when accessed so that no more than one
	// instance is created.
	// Finally the instance of the single settings is returned.
	public static Settings getInstance() {
		if (instance == null) {
			synchronized (Logger.class) {
				if (instance == null)
					instance = new Settings();
			}
		}
		return instance;
	}
	
	public void updateCpuCores(int num){
		cpuCores=num;
	}
	
	public void updateOpenWindows(boolean value){
		multipleWindowsOpen=value;
	}
	
	public void updateTileOpenWindows(boolean value){
		tileOpenWindows=value;
	}
	
	public void updateTileOpenWindowsResize(boolean value){
		tileWindowsOpenResize=value;
	}
	

	public int getCpuCores(){
		return cpuCores;
	}
	
	public boolean getOpenWindows(){
		return multipleWindowsOpen;
	}
	
	public boolean getTileOpenWindows(){
		return tileOpenWindows;
	}
	
	public boolean getTileOpenWindowsResize(){
		return tileWindowsOpenResize;
	}
	
	public int getSystemCores(){
		Runtime rt = Runtime.getRuntime();
		return cpuCores=rt.availableProcessors();
	}
	
}
